<template>
  <div>
    <el-tree :data="data" 
      :props="defaultProps"
      @node-click="nodeClick">
    </el-tree>
  </div>
</template>
<script>
import PubSub from 'pubsub-js'
export default {
  data() {
    return {
      
      data: [],
      defaultProps: {
        children: "children",
        label: "name",
      },
    };
  },
  created() {
    this.getDateList();
  },
  methods: {
    nodeClick(data) {
      console.log("被点击的对象为",data);
      if(data.catLevel==3) {
        //两个参数 第一个参数发布时间的参数名称
        //        第二参数 需要发布的值
        PubSub.publish("node-tree-click",data);
      }
    },
    getDateList() {
      this.$http({
        url: this.$http.adornUrl("/product/category/tree/list"),
        method: "get",
        params: this.$http.adornParams(),
      }).then(({ data }) => {
        console.log(data);
        this.data = data.page;
      });
    },
  },
};
</script>
